﻿using CommandProcessor.Command;
using Data.Infrastructure;
using Data.Repositories;
using Domain.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Handlers
{
    public class DeleteBOMAccessories_DetailHandler : ICommandHandler<DeleteBOMAccessories_DetailCommand>
    {
        private readonly IBOMAccessorie_DetailsRepository BOMAccessories_DetailRepository;
        private readonly IUnitOfWork unitOfWork;
        public DeleteBOMAccessories_DetailHandler(IBOMAccessorie_DetailsRepository BOMAccessories_DetailRepository, IUnitOfWork unitOfWork)
        {
            this.BOMAccessories_DetailRepository = BOMAccessories_DetailRepository;
            this.unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(DeleteBOMAccessories_DetailCommand command)
        {
            var BOMAccessories_Detail = BOMAccessories_DetailRepository.GetById(command.ID);
            BOMAccessories_DetailRepository.Delete(BOMAccessories_Detail);
            unitOfWork.Commit();
            return new CommandResult(true);
        }


        public ICommandResult ExecuteRange(IEnumerable<DeleteBOMAccessories_DetailCommand> commands)
        {
            var ids = commands.Select(y => y.ID);
            BOMAccessories_DetailRepository.Delete(x => ids.Contains(x.ID));
            unitOfWork.Commit();
            return new CommandResult(true);
        }
        public ICommandResult DeleteRange(IEnumerable<DeleteBOMAccessories_DetailCommand> commands)
        {
            throw new NotImplementedException();
        }
    }
}
